<?php

namespace App\Console\Commands\Image;

use App\Service\LogTrait;
use GuzzleHttp\Client;
use GuzzleHttp\Cookie\CookieJar;
use Illuminate\Console\Command;

class Mm131 extends Command
{
    use LogTrait;

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'image:mm131';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * @var $http Client
     */
    protected $http;

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @throws \Exception
     * @return mixed
     */
    public function handle()
    {
        try{
            $this->logName = $this->signature;
            $url = 'https://www.mm131.net/xinggan/2670.html';

            $this->http = new Client([
                'cookies' => true,
                'headers' => [
                ]
            ]);
            $this->getList($url);

        }catch (\Exception $e){
            $this->logWrite($e->getMessage());
            $this->logWrite($e->getTraceAsString());
        }
    }


    public function getList($url)
    {
        $result = $this->http->get($url);

        $image  = $this->http->get('https://img1.mm131.me/pic/2670/1.jpg');
        file_put_contents(public_path('1.jpg'), $image->getBody()->getContents());
    }

    protected function setHttp()
    {
        $this->http = new Client([
            'cookies' => true,
            'headers' => [
                'Referer' => 'https://www.mm131.net/qingchun/5031.html'
            ]
        ]);
    }

}
